package cn.tedu.boottext33.controller;

import cn.tedu.boottext33.mapper.MineMapper;
import cn.tedu.boottext33.vo.Mine;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class MineController {
    @Autowired(required = false)
    MineMapper mapper;

    @RequestMapping("/insert")
    public String insert(Mine mine){
        System.out.println("mine = " + mine);
        mapper.insert(mine);
        return "增加成功!<a href='/select'>放回信息列表</a>";
    }

    @RequestMapping("/select")
    public String select(){
        List<Mine> list = mapper.select();

        String html="<table border=1>";
        html+="<caption>员工列表</caption>";
        html+="<tr><th>id</th><th>名字</th><th>工作</th><th>工资</th><th>操作</th></tr>";
        //添加员工信息
        for (Mine mine : list) {
            html+="<tr>";
            html+="<td>"+mine.getId()+"</td>";
            html+="<td>"+mine.getName()+"</td>";
            html+="<td>"+mine.getJob()+"</td>";
            html+="<td>"+mine.getSal()+"</td>";
            html+="<td><a href='/delete?id="+mine.getId()+"'>删除</a></td>";
            html+="</tr>";
        }
        html+="</table>";
        return html;
    }

    @RequestMapping("/delete")
    public String delete(int id){
        System.out.println("id = " + id);
        mapper.delete(id);
        return "删除成功<a href='/select'>返回参数列表</a>";
    }

    @RequestMapping("/update")
    public String update(Mine mine){
        System.out.println("mine = " + mine);
        mapper.update(mine);
        return "修改成功!<a href='select'>返回信息列表</a>";
    }


}
